<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\member\controller;

/** 控制器类引入区 **/
use app\common\model\UserPay as UserPayModel;
use app\common\model\ViperUser as ViperUserM;
use app\common\model\ViperUserCash as ViperUserCashM;
/** 模型类引入区 **/

/** 核心或第三方类引入区 **/
use think\Db;

/**
 *  提现 控制器
 */
class Withdrawal extends Base
{
    public $noNeedLogin = [''];

    /**
     *  提现信息
     **/
    public function cashInfo()
    {
        $user_id    = $this->user_id;
        $userInfo   = ViperUserM::where('id',$user_id)->find();
        $data = [
            'money'=>$userInfo['money'],
        ];

        $this->result('获取成功',$data,200);
    }


    /**
     *  发起 提现
     **/
    public function cashUp(){
        if($this->request->ispost()) {
            $user_id    = $this->user_id;
            $data       = $this->request->post();
            if(empty($data['money']))    $this->result('请填写提现金额','',204);
            if(empty($data['pay_id']))    $this->result('请选择收款方式','',204);

            $UserPayModel  =   new UserPayModel();
            $UserPayInfo          =   $UserPayModel->where(['uv_id'=>$user_id,'id'=>$data['pay_id']])->find();

            switch ($UserPayInfo['type'])
            {
                //支付宝
                case 1:
                    $row['alipay_num']    = $UserPayInfo['alipay_num'];
                    $row['alipay_name']   = $UserPayInfo['alipay_name'];
                    break;
                //银行卡
                case 2:

                    $row['bank_num']    = $UserPayInfo['bank_num'];
                    $row['open_bank']   = $UserPayInfo['open_bank'];
                    $row['bank_name']   = $UserPayInfo['bank_name'];
                    break;
            }

            $ViperUserCashM = new ViperUserCashM();
            $result = $ViperUserCashM->addUp($user_id,$UserPayInfo['type'],$data['money'],$row,'');
            if($result['code'] == 0)
            {
                $this->result('申请成功','',200);
            }else{
                $this->result($result['msg'],'',204);
            }
        }else{
            $this->result('非法请求','',204);
        }
    }


    /**
     *  提现记录
     **/
    public function cashList()
    {
        $limit      = $this->request->post('limit',10);
        $ViperUserCashM      = new ViperUserCashM();
        $list       = $ViperUserCashM->getList($this->user_id,$limit);
        $this->result('获取成功',$list,200);
    }



}
